// pages/report/index.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    status: true,
    status_arr: [
      {unusual: false, name: '无下列情况，身体健康', checked: false, disabled: false,},
      {unusual: true, name: '近十五日内居中或者到过国内高风险、中风险地区', checked: false, disabled: false,},
      {unusual: true, name: '最近十五日接触过新冠肺炎感染者', checked: false, disabled: false,},
      {unusual: true, name: '发热(37.3度以上)、咳嗽、乏力、呼吸困难', checked: false, disabled: false,},
      {unusual: true, name: '医学隔离', checked: false, disabled: false,},
      {unusual: true, name: '疑似病例', checked: false, disabled: false,},
      {unusual: true, name: '确诊病例', checked: false, disabled: false,},
      {unusual: true, name: '近十五日内在境外居住过或者在境外居住', checked: false, disabled: false,},
    ],
    is_home: false,
    temp: 36,
    address: ""
  },
  report() {
    //report
    var status_info = [];
    for(var index in this.data.status_arr){
      if(this.data.status_arr[index].checked){
        status_info.push(this.data.status_arr[index])
      }
    }
    var userId = wx.getStorageSync('userInfo')['id'];
    app.data.utils.request({
      url: app.data.api.report+ userId + ".api",
        data: {
          temperature:this.data.temp, // 体温
          status_info:JSON.stringify(status_info),
          is_home: this.data.is_home? 1: 0,
          is_except:this.data.status? 0: 1,
          address: this.data.address
        },
        method: 'post',
        success: (data) => {
          wx.showToast({
            title: '上报成功',
          })
        }
    });
  },
  changeStatus: function(e){
    console.log(e);
    var checked_data = e.detail.value;
    var is_normanl = false;
    for(var index in checked_data){
      this.data.status_arr[index]['checked'] = true;
      if(checked_data[index] == 0){
        is_normanl = true;
        
        for(var ind in this.data.status_arr){
          if(ind != 0){
            this.data.status_arr[ind]['checked'] = false;
            this.data.status_arr[ind]['disabled'] = false;
          }
        }
        this.setData({
          status_arr: this.data.status_arr
        })
        
        break;
      }else{
        this.setData({
          status: false
        })
      }
    }

  },
  changeHome: function(e){
    console.log(e);
    if(e.detail.value){
      this.setData({
        is_home: true
      })
    }else{
      this.setData({
        is_home: false
      })
    }
  },
  changeAdress: function(e){
    this.setData({
      address: e.detail.value
    })
  },
  changeTemp: function(e){
    this.setData({
      temp: e.detail.value
    })
  },
  submit: function(e){
    var userId = wx.getStorageSync('userInfo')['id'];
    app.data.utils.request({
      url: app.data.api.formID + "/" + userId + "/formID.api",
      data: {form_id: e.detail.formId},
      method: 'post',
    })
   this.report();

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})